<p>Non-static initializers are rarely used, and can be confusing for most developers because they only run when new class instances are created. When
possible, non-static initializers should be refactored into standard constructors or field initializers.</p>
<h2>Noncompliant Code Example</h2>
<pre>
class MyClass {
  private static final Map&lt;String, String&gt; MY_MAP = new HashMap&lt;String, String&gt;() {

    // Noncompliant - HashMap should be extended only to add behavior, not for initialization
    {
      put("a", "b");
    }

  };
}
</pre>
<h2>Compliant Solution</h2>
<pre>
class MyClass {
  private static final Map&lt;String, String&gt; MY_MAP = new HashMap&lt;String, String&gt;();

  static {
    MY_MAP.put("a", "b");
  }
}
</pre>
<p>or using Java 9 <code>Map.of</code>:</p>
<pre>
class MyClass {
  // Compliant
  private static final Map&lt;String, String&gt; MY_MAP = java.util.Map.of("a", "b");
}
</pre>
<p>or using Guava:</p>
<pre>
class MyClass {
  // Compliant
  private static final Map&lt;String, String&gt; MY_MAP = ImmutableMap.of("a", "b");
}
</pre>

